package cn.fl.appeal.service.impl;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.thirdauth.facade.auth.api.IApiAppealApplyService;
import cmm.thirdauth.facade.auth.dto.*;
import cmm.thirdauth.facade.base.dto.ApiThirdAuthPageReq;
import cmm.thirdauth.facade.base.dto.ApiThirdAuthPageResp;
import cmm.thirdauth.facade.base.dto.ApiThirdAuthReqDTO;
import cmm.thirdauth.facade.base.dto.ApiThirdAuthReqHeadDTO;
import cn.fl.appeal.service.LiveAppealService;
import cn.fl.framework.base.context.CurrentThreadContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LiveAppealServiceImpl implements LiveAppealService {

    @Autowired
    private IApiAppealApplyService iApiAppealApplyService;

    @Override
    public ApiThirdAuthPageResp searchListPage(ApiThirdAuthReqDTO<ApiThirdAuthPageReq<ApiApplyListQueryReqDTO>> authReqDTO) {
        DataResultDTO dataResultDTO = iApiAppealApplyService.applyListPage(authReqDTO);
        ApiThirdAuthPageResp data = (ApiThirdAuthPageResp) dataResultDTO.getData();
        return data;
    }

    @Override
    public ApiAppealRespDTO queryAppealDetail(Long appealId) {

        ApiThirdAuthReqDTO<ApiApplyDetailReqDTO> authReqDTO = new ApiThirdAuthReqDTO<>();
        ApiApplyDetailReqDTO detailReqDTO = new ApiApplyDetailReqDTO();
        detailReqDTO.setAppealId(appealId);
        detailReqDTO.setCurrentUserId(CurrentThreadContext.getCurrentUserId());
        authReqDTO.setBody(detailReqDTO);
        ApiThirdAuthReqHeadDTO headDTO = new ApiThirdAuthReqHeadDTO();
        headDTO.setbId("5620526c50544796a414013337900ba4");
        headDTO.setpId("SQZS82JDKS999DDE");
        authReqDTO.setHead(headDTO);
        DataResultDTO dataResultDTO = iApiAppealApplyService.appealDetail(authReqDTO);
        ApiAppealRespDTO respDTO = (ApiAppealRespDTO) dataResultDTO.getData();
        return respDTO;
    }

    @Override
    public boolean updateFileStatus(String validType, String fileId) {

        ApiThirdAuthReqDTO<ApiApplyFileStateUpdateReqDTO> thirdAuthReqDTO = new ApiThirdAuthReqDTO<>();
        ApiApplyFileStateUpdateReqDTO updateReqDTO = new ApiApplyFileStateUpdateReqDTO();
        updateReqDTO.setFileId(Long.valueOf(fileId));
        updateReqDTO.setStatus(Short.valueOf(validType));
        thirdAuthReqDTO.setBody(updateReqDTO);
        ApiThirdAuthReqHeadDTO headDTO = new ApiThirdAuthReqHeadDTO();
        headDTO.setbId("5620526c50544796a414013337900ba4");
        headDTO.setpId("SQZS82JDKS999DDE");
        thirdAuthReqDTO.setHead(headDTO);
        DataResultDTO dataResultDTO = iApiAppealApplyService.updateFileState(thirdAuthReqDTO);
        if (dataResultDTO.getSuccess() == 1) {
            return true;
        }
        return false;
    }

    @Override
    public boolean updateAppealInfo(String appealId, String busRem) {

        ApiThirdAuthReqDTO<ApiCmmFivAppealReqDTO> thirdAuthReqDTO = new ApiThirdAuthReqDTO<>();
        ApiCmmFivAppealReqDTO appealReqDTO = new ApiCmmFivAppealReqDTO();
        appealReqDTO.setId(Long.valueOf(appealId));
        appealReqDTO.setBusRem(busRem);
        thirdAuthReqDTO.setBody(appealReqDTO);
        ApiThirdAuthReqHeadDTO headDTO = new ApiThirdAuthReqHeadDTO();
        headDTO.setbId("5620526c50544796a414013337900ba4");
        headDTO.setpId("SQZS82JDKS999DDE");
        thirdAuthReqDTO.setHead(headDTO);
        DataResultDTO dataResultDTO = iApiAppealApplyService.update(thirdAuthReqDTO);
        if (dataResultDTO.getSuccess() == 1) {
            return true;
        }
        return false;
    }
}
